function [h_hat,singular]=channel_estimation(h,noise,rho,nt,nr,T,v_single)

v=[];
v=noise*randn(nr,T) + j*noise*randn(nr,T);
%for m=1:T
%	v=horzcat(v,v_single);
%end

%if T=0, that means we are not training the channel, return h
if(T==0)
	h_hat=h;
else

	%determine output for given training symbols
	s=get_training_data(nt,nt*T*2);
	y=sqrt(rho/nt)*h*s+v;


	h_hat=0;
	%estimate channel
	h_hat=h_hat+sqrt(nt/rho)*y*ctranspose(s)*pinv(s*ctranspose(s));
	if(cond(h_hat)>100)
		h_hat=sqrt(nt/rho)*y*ctranspose(s)*pinv( rho/nt*s*ctranspose(s) + diag(ones(nt,1)) );
	end
end


if(cond(h_hat) > 100)
singular=1;
else
singular=0;
end;